﻿--[[
   @brief    model for new ui banner
   @author   hqzheng
   @version  1.0
   @date     2016-01-21
--]]

ierd_tgp.tpf_ui.Require("game_id.lua");

banner_model_const = {
    PRIVILEGE_DESC_MAX_LEN = 127;
};

StatePriority = {
    kPluginClosed = 0,   -- 插件已关闭状态，优先级最低
    kGameStatic = 1,     -- 游戏静态状态
    kPluginStatic = 2,   -- 插件静态状态
    kPluginDynamic = 3,  -- 插件动态状态, 优先级最高
    kGameDynamic = 4     -- 游戏动态状态
};

subscription_state = {
    kStateInvalid     = -1,
    kStateNormal      = 0,  -- 预约
    kStatePurchasable = 1,  -- 可购买（付费游戏全量后的状态）
    kStateDownload    = 2,  -- 可下载
    kStateRelease     = 4,  -- 可玩（免费游戏全量后的状态）
    kStatePurchased   = 8,  -- 已购买
    kStateMaintein    = 16, -- 维护中
};

banner_qos_action = {
    kActionDownloadSubscribed = "download_subscribed",
    kActionCancelDownloadSubscribed = "cancel_download_subscribed",
    kActionBannerDbClick = "banner_dbclick"
};

banner_model =
{
    GAME_CENTER_GAME_ID = 55555;     -- 游戏中心游戏ID定义为0
    ITEM_COUNT_PER_TIME = 10;

    last_selected_game_id_ = nil;
    last_selected_ctrl_id_ = nil;

    module_url = {
        ["1"] = LoadStr("GAME_CENTER_URL"),           -- game_center
        ["2"] = LoadStr("TEST_LOL_HELPER_URL"),              -- lol_helper
        ["3"] = LoadStr("TEST_CF_HELPER_URL"),               -- cf_helper
        ["4"] = LoadStr("TEST_DNF_HELPER_URL"),              -- dnf_helper
    };

    -- 模块信息
    module_info = {
    };

    def_module_color = "COLOR:RGB:25,31,45";                                -- 默认游戏背景颜色
    def_module_image = "newui_mainframe\\common_mode.png?308,17,450,378";    -- 默认游戏背景图片
    def_banner_color = "COLOR:RGB:48,48,51";
    -- 获取礼包窗口id
    update_last_progress = 0;

    visible_game_list = nil;
    game_base_info_list;
    game_state_list;
    plugin_state_list;
    all_game_servers;
    game_release_list;

    first_show = true;

    -- netbar
    GAME_LIST_TYPE_MY_GAME = 10;
    GAME_LIST_TYPE_CURRENT_GAME = 14;
    game_list_type = 0;
    is_netbar = 0;

    newbie_guide_show = false;
    newbie_already_show = false;

    cur_hover_banner_game_id = 0;

    pre_visible_game_list_count = 0;
    pre_visible_game_list_first_game_id = 0;

    guide_update_game_id = 0;
    guide_update_zone_id = 0;

    op_from_my_app_list = false;

    module_info = {};

    GAME_UPDATE_PAUSE_STATUS = {
        NO_PAUSE = 0,
        PAUSE = 1,
    };

    banner_type = {
        NORMAL   = 0,  -- 普通banner  
        BIGEVENT = 1,  -- 大事件banner
    };

    -- 发行渠道定义
    distribution_channels = {
        CHANNELS_NORMAL = 1,
        CHANNELS_RAIL   = 2,
    };

    ctrl_id_to_off_shell_tips = {};
    ctrl_id_to_lack_space_tips = {};
    off_shell_announcement_url = LoadStr("OFF_SHELL_ANNOUNCE_URL");

    follow_game_list_req_url =
        LoadStr("QUERY_SUBMIT_LIST_URL");

    follow_game_list = nil;

    -- GameTips上报相关数据
    game_tips_shown = nil;

    -- 游戏版本公告数据
    game_version_post_oss_url = LoadStr("GAME_VER_POST_URL");
    game_version_post_oss_templet_name = "game_version_post";
    game_version_post_data_timestamp = nil;
    game_version_post_data = {};

    -- 预约游戏
    subscription_list_req_url = LoadStr("QUERY_SUBSCRIBE_URL");
    subscription_delete_req_url = LoadStr("DELETE_SUBSCRIBE_URL");
    subscription_config_url = LoadStr("GL_GAME_CONFIG_URL");
    subscription_list_info = {};
    subscription_config_list = {};
    subscription_cancel_download_list = {};
    subscription_state_notify_list = {};
    subscription_transfered_list_info = {};
    has_load_local_subscription_info = false;
    has_subscription_info_changed = false;
    auto_download_subscribed_app = false;
    subscription_first_time = 0;
    subscription_app_base_info_check_times = 0;
    subscription_app_base_info_check_list = {};
    subscription_list_rsp_cache = "";

    init = function()
        banner_model.inner_log("init");

        banner_model.visible_game_list = ierd_tgp.game_library.Game_list:new();
        banner_model.plugin_state_list = ierd_tgp.game_library.PluginStateList:new();
        banner_model.init_all_game_servers();
        banner_model.init_all_game_base_info();
        banner_model.init_all_game_state_info();
        banner_model.init_all_game_release_info();

        -- 初始化
        banner_model.game_tips_shown = {};

        banner_model.query_game_version_post_cfg();

        banner_model.load_subscription_settings();
        -- jameszhai: 添加请求游戏信息的服务
        comm_center.reg_service("GetGameIconByID_Svr", "banner_model.OnGetGameIconByID");
        comm_center.reg_service("i_service_is_game_in_subscription", "banner_model.is_game_in_subscription_list_svr");
        comm_center.reg_service("i_service_get_subscription_list", "banner_model.get_subscription_list_svr");
    end;

    uninit = function()
        banner_model.inner_log("uninit");
        banner_model.visible_game_list:delete();
        banner_model.uninit_all_game_base_info();
        banner_model.uninit_all_game_state_info();
        banner_model.plugin_state_list:delete();
        banner_model.uninit_all_game_servers();
        banner_model.uninit_all_game_release_info();
    end;

    init_all_game_servers = function()
        banner_model.inner_log("init_all_game_servers");
        banner_model.all_game_servers = {};
        banner_model.all_game_servers.game_count = 0;
        banner_model.all_game_servers.acce_enabled = 0;   -- 没有地方在使用
        banner_model.all_game_servers.gameid2servers = {};
    end;

    init_all_game_base_info = function()
        banner_model.inner_log("init_all_game_base_info");
        banner_model.game_base_info_list = {};
        banner_model.game_base_info_list.count = 0;
        banner_model.game_base_info_list.game_base_info = {};
    end;
    
    init_all_game_state_info = function()
        banner_model.inner_log("init_all_game_state_info");
        banner_model.game_state_list = {};
        banner_model.game_state_list.count = 0;
        banner_model.game_state_list.game_state = {};
    end;

    init_all_game_release_info = function()
        banner_model.inner_log("init_all_game_release_info");
        banner_model.game_release_list = {};
    end;

    uninit_all_game_servers = function()
        banner_model.inner_log("uninit_all_game_servers");
        if nil == banner_model.all_game_servers or
           nil == banner_model.all_game_servers.gameid2servers then
            banner_model.inner_log("banner_model.all_game_servers is nil");
            return;
        end;

        for game_id, servers in pairs(banner_model.all_game_servers.gameid2servers) do
            if nil ~= banner_model.all_game_servers.gameid2servers[game_id] then
                banner_model.all_game_servers.gameid2servers[game_id]:delete();
                banner_model.all_game_servers.gameid2servers[game_id] = nil;
            end;
        end;

        banner_model.all_game_servers = nil;
    end;

    uninit_all_game_base_info = function ()
        banner_model.inner_log("uninit_all_game_base_info");
        if nil == banner_model.game_base_info_list or 
            nil == banner_model.game_base_info_list.game_base_info then
                banner_model.inner_log("uninit_all_game_base_info");
            return;
        end

        for i = 0, (banner_model.game_base_info_list.count - 1) do
            if nil ~= banner_model.game_base_info_list.game_base_info[i] then
                banner_model.game_base_info_list.game_base_info[i]:delete();
                banner_model.game_base_info_list.game_base_info[i] = nil;
            end;
        end;

        banner_model.game_base_info_list = nil;
    end;

    uninit_all_game_state_info = function()
         banner_model.inner_log("uninit_all_game_state_info");
         if nil == banner_model.game_state_list or
           nil == banner_model.game_state_list.game_state then
            banner_model.inner_log("banner_model.game_state_list is nil");
            return;
        end;

        for i = 0, (banner_model.game_state_list.count - 1) do
            if nil ~= banner_model.game_state_list.game_state[i] then
                banner_model.game_state_list.game_state[i]:delete();
                banner_model.game_state_list.game_state[i] = nil;
            end;
        end;

        banner_model.game_state_list = nil;
    end;

    uninit_all_game_release_info = function()
        banner_model.inner_log("uninit_all_game_release_info");
        if nil == banner_model.game_release_list then
            return;
        end;

        banner_model.game_release_list = nil;
    end;

    inner_log = function (msg, core_msg)
        base_utility.log(string.format("[banner_model] %s", msg), core_msg);
    end;

    -- 服务定义
    OnGetGameIconByID = function(zParam)
        if (nil == zParam) or (nil == zParam["GameID"]) then
            banner_model.inner_log("Request game info, GameID is null.", true);
            return nil;
        end;

        local   zTemp = banner_model.get_game_base_info(zParam["GameID"]);

        if (nil ~= zTemp) then
            local   zIcon = {};
            zIcon["Icon"] = zTemp.banner_icon_url;
            return zIcon;
        else
            return {};
        end;
    end;

    -- [return]base_info: ierd_tgp.game_library.GameBaseInfo
    get_game_base_info = function(game_id)
        if game_id == nil then
            banner_model.inner_log("get_game_base_info, game_id is nil");
            return nil;
        end
        if game_id ~= nil and type(game_id) ~= "number" then
            game_id = tonumber(game_id);
        end
        --banner_model.inner_log("get_game_base_info, game_id: " .. game_id);
        
        if banner_model.game_base_info_list == nil then
            return nil;
        end;
        
        for i = 0, (banner_model.game_base_info_list.count - 1) do
            if banner_model.game_base_info_list.game_base_info[i].id == game_id then
                return banner_model.game_base_info_list.game_base_info[i];
            end;
        end;

        return nil;
    end;

    -- [return]game_state: ierd_tgp.game_library.GameState
    get_game_state = function(game_id)
        -- banner_model.inner_log("get_game_state, game_id: " .. game_id);
        
        if banner_model.game_state_list == nil then
            banner_model.inner_log("[get_game_state]sate list is nil, game_id: " ..
                    tostring(game_id),
                true);
            return nil;
        end;
        
        for i = 0, (banner_model.game_state_list.count - 1) do
            if banner_model.game_state_list.game_state[i].iGame_id == game_id then
                return banner_model.game_state_list.game_state[i];
            end;
        end;

        banner_model.inner_log("[get_game_state]sate NOT FOUND, game_id: " ..
                tostring(game_id),
            true);
        
        return nil;
    end;
    
    -- 获取当前玩家是否可以下载当前游戏
    -- [return]release_statu: boolean
    get_game_release_status = function(game_id)
        if nil == banner_model.game_release_list then
            return false;
        end

        for k, v in pairs(banner_model.game_release_list) do
            if k == game_id then
                return v;
            end
        end
        return false;
    end;

    get_plugin_state = function(game_id)
        --banner_model.inner_log("get_plugin_state, game_id: " .. game_id);
        
        if banner_model.plugin_state_list == nil then
            return nil;
        end;
        
        for i = 0, (banner_model.plugin_state_list.count - 1) do
            if banner_model.plugin_state_list.plugin_state[i].game_id == game_id then
                return banner_model.plugin_state_list.plugin_state[i];
            end;
        end;
        
        return nil;
    end;

    -- [return]servers: ierd_tgp.game_library.GameServers
    get_game_servers = function(game_id)
        banner_model.inner_log("get_game_servers, game_id: " .. game_id);
        
        if banner_model.all_game_servers == nil then
            banner_model.inner_log("banner_model.all_game_servers is nil");
            return nil;
        end;
       
        return banner_model.all_game_servers.gameid2servers[game_id];
    end;

    -- [return]server: 通过server_id来获取pre_update字段值
    get_server_by_zoneid = function(game_id, zone_id)
        banner_model.inner_log(string.format("get_server_by_zoneid, gameid:%d, zone id:%d",
        game_id, zone_id));
        
        local servers = banner_model.get_game_servers(game_id);
        if (servers ~= nil and servers.server_count > 0) then
            for i = 0, (servers.server_count - 1) do
                local server = servers.servers[i];  
                if server ~= nil and server.id == zone_id then
                    return server;
                end;
            end;
        end;
        
        return nil;
    end;
    
    get_privilege_desc = function(game_id)
        banner_model.inner_log("get_privilege_desc, game_id: " .. game_id);

        local str = NewStr(banner_model_const.PRIVILEGE_DESC_MAX_LEN);
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        
        game_lib:get_privilege_desc(game_id, str, banner_model_const.PRIVILEGE_DESC_MAX_LEN);
        banner_model.inner_log("[banner_model]got_privilege_desc:".. str);
        return str;
    end;


    has_game_is_running = function()
        for i = 0, (banner_model.game_state_list.count - 1) do
            if banner_model.game_state_list.game_state[i].iState == ierd_tgp.game_library.GAME_STATE_RUNNING then
                return 1;
            end;
        end;
        return 0;
    end;


    -- 通过game_id 获取对应的banner模块信息 
    get_banner_module_info_by_game_id = function (game_id)
        if nil == game_id then
            banner_model.inner_log("get_banner_module_info, game_id is nil");
            return nil;
        end
        local num_game_id = tonumber(game_id);
        if nil == num_game_id then
            banner_model.inner_log("get_banner_module_info, game_id tonumber is nil");
            return nil;
        end

        if banner_model.module_info == nil then 
            banner_model.inner_log("get_banner_module_info, module_info is nil");
            return nil;
        end
        
        return banner_model.module_info[num_game_id];
    end;

     
    -- 获取游戏中心模块信息
    get_game_center_module_info = function ()
        banner_model.inner_log("get_game_center_module_info");
        return banner_model.module_info[banner_model.GAME_CENTER_GAME_ID]; 
    end;

    on_get_follow_game_list = function (result)
        base_utility.log("[on_get_follow_game_list]received cfg:" .. result);
        local success, result_table, crc = 
            base_utility.cfg_string_to_table(result, "get_follow_game_list");
        if success then
            banner_model.follow_game_list = result_table;
            banner_view.refresh_game_list(true);
        end;
    end;

    is_in_follow_list = function (game_id)
        local is_in_list = false;
        if nil ~= banner_model.follow_game_list then
            for k, v in pairs(banner_model.follow_game_list) do
                if game_id == v then
                    is_in_list = true;
                    break;
                end
            end
        end
        return is_in_list;
    end;

        -- 从OSS拉取游戏版本公告配置数据
    query_game_version_post_cfg = function()
        base_utility.log("[banner_model]query game version post cfg]");
        base_utility.curl_request_async (banner_model.game_version_post_oss_url, 
            "banner_model.on_get_vsersion_post_result", true);
    end;

    on_get_vsersion_post_result = function(result)
        base_utility.log("[banner_model]on_get_vsersion_post_result called ");
        local status,tbl = base_utility.oss_string_to_table(result, 
            banner_model.game_version_post_oss_templet_name);
        if status == true then
            if tbl ~= nil and tbl["data"] ~= nil and table.getn(tbl["data"]) > 0 then
                if tbl["update_time"] ~= nil and tbl["update_time"] ~= "" then
                    local cfg_timestamp = tonumber(tbl["update_time"]);
                    if banner_model.game_version_post_data_timestamp ~= nil then 
                        local data_timestamp = banner_model.game_version_post_data_timestamp;
                        if data_timestamp and cfg_timestamp and data_timestamp < cfg_timestamp then
                            base_utility.log("[banner_model]on_get_vsersion_post_result updating");
                            for i, post_data in pairs(tbl["data"]) do
                                banner_model.game_version_post_data[tonumber(post_data.game_id)] = 
                                    post_data;
                            end
                            banner_model.game_version_post_data_timestamp = cfg_timestamp;
                        else
                            -- 无需更新
                            base_utility.log("[banner_model]on_get_vsersion_post_result: not need update");
                        end
                    else 
                        -- 首次更新
                        base_utility.log("[banner_model]on_get_vsersion_post_result: first update");
                        for i, post_data in pairs(tbl["data"]) do
                            banner_model.game_version_post_data[tonumber(post_data.game_id)] = 
                                post_data;
                        end
                        banner_model.game_version_post_data_timestamp = cfg_timestamp;
                    end
                end
            else
                base_utility.log("[banner_model] on_get_vsersion_post_result is nil");
            end
        else
            base_utility.log("[banner_model] on_get_vsersion_post_result: rsp is failed");
        end
    end;

    handle_oss_version_post = function(post_data, game_update_target_ver, game_id)
        if post_data ~= nil and post_data["detail_url"] ~= nil then 
            local update_target_ver_cfg = post_data["update_target_version"];
            if update_target_ver_cfg ~= nil then
                if game_update_target_ver ~= nil and game_update_target_ver ~= "" then 
                    if update_target_ver_cfg == game_update_target_ver then
                        return post_data["detail_url"];
                    else
                        base_utility.log(
                            "[banner_model]update version not match post_url verison of oss_cfg, game_id:"
                            .. game_id .. ", update version: " .. game_update_target_ver);
                    end
                else
                    base_utility.log("[banner_model]game update version is nil, game_id:" .. game_id );
                end
            else
                base_utility.log(
                    "[banner_model]post_url update version from oss_cfg is nil, game_id:" .. game_id);
            end
        else
            base_utility.log("[banner_model]post_url data from oss_cfg is nil, game_id:" .. game_id);
        end
        return;
    end;

    get_off_shell_tips_ctrl_id = function (game_id)
        if nil == banner_model.ctrl_id_to_off_shell_tips then
            return 0;
        end
        local ctrl_id = 0;
        for k, v in pairs(banner_model.ctrl_id_to_off_shell_tips) do
            if nil ~= v and v:get_game_id() == game_id then
                ctrl_id = k;
                break;
            end
        end

        return ctrl_id;
    end;

    get_off_shell_tips = function (tips_ctrl_id)
        if nil == banner_model.ctrl_id_to_off_shell_tips then
            return nil;
        end
        return banner_model.ctrl_id_to_off_shell_tips[tips_ctrl_id];
    end;

    get_lack_space_tips_ctrl_id = function (game_id)
        if nil == banner_model.ctrl_id_to_lack_space_tips then
            return 0;
        end
        local ctrl_id = 0;
        for k, v in pairs(banner_model.ctrl_id_to_lack_space_tips) do
            if nil ~= v and v:get_game_id() == game_id then
                ctrl_id = k;
                break;
            end
        end

        return ctrl_id;
    end;

    get_lack_space_tips = function (tips_ctrl_id)
        if nil == banner_model.ctrl_id_to_lack_space_tips then
            return nil;
        end
        return banner_model.ctrl_id_to_lack_space_tips[tips_ctrl_id];
    end;

    get_game_update_pause_status = function (game_id)
        banner_model.inner_log(
            string.format("[get_game_update_pause_status]game_id:%d", game_id));       
        local param = {};
        param["game_id"] = game_id;
        local data_out = comm_center.call_service("SvrGetGameUpdateStatus", param);
        local pause_status = 0;
        local update_progress = 0;
        if nil ~= data_out.pause_status then
            pause_status = data_out.pause_status;
        end
        if nil ~= data_out.update_progress then
            update_progress = data_out.update_progress;
        end

        return pause_status, update_progress;
    end;

    -- 获取游戏状态优先级
    get_gamestate_priority = function(game_state)
        if game_state == ierd_tgp.game_library.GAME_STATE_NORMAL or 
            game_state == ierd_tgp.game_library.GAME_STATE_UNKNOWN or
              game_state == ierd_tgp.game_library.GAME_STATE_SERVER_UNAVAILABLE then
                return StatePriority.kGameStatic;
        else
            return StatePriority.kGameDynamic;
        end;
    end;

    -- 获取助手状态优先级
    get_pluginstate_priority = function (plugin_state)
        if plugin_state == ierd_tgp.game_library.KNEEDUPDATE or 
            plugin_state == ierd_tgp.game_library.KUPDATECANCELED then
                return StatePriority.kPluginStatic;
        elseif plugin_state == ierd_tgp.game_library.KWAITTINGUPDATE or
                plugin_state == ierd_tgp.game_library.KUPDATTING or
                  plugin_state == ierd_tgp.game_library.KUPDATEFAIL then
                    return StatePriority.kPluginDynamic;
        else
            return 0;
        end
    end;

    is_plugin_priority_higher = function(plugin_state, game_state)
        if plugin_state == nil then
            plugin_state = 0;
        end
        if game_state == nil then
            game_state = 0;
        end
        if banner_model.get_pluginstate_priority(plugin_state) > banner_model.get_gamestate_priority(game_state) then
            return true;
        else
            return false;
        end
    end;

    get_sub_url_by_game_id = function(game_id, sub_key)
        local module_info = banner_model.get_banner_module_info_by_game_id(game_id);
        if module_info ~= nil then
            local sub_urls_json = module_info.sub_url_list;
            if sub_urls_json ~= nil and sub_urls_json ~= "" then
                local urls_tbl = base_utility.json_to_table(sub_urls_json);
                if urls_tbl ~= nil and type(urls_tbl) == 'table' then
                    return urls_tbl[sub_key];
                end
            end
        end
        return nil;
    end;

    -- 是否是切换产品线游戏
    is_switch_branch_game = function (game_id)
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        local branch_id = 0; 
        if nil ~= game_lib then
            branch_id = game_lib:GetDestBranchIDToSwitch(game_id);
        end
        banner_model.inner_log(
            string.format("[is_switch_branch_game]branch_id:%d", branch_id));  
        local is_switch_branch = false;
        if 0 ~= branch_id then
            is_switch_branch = true;
        end
        return is_switch_branch;
        -- return true;
    end;

    is_game_last_action_switch_branch = function(game_id)
        local is_switch_branch = 0;
        local z_param = {};
        z_param["game_id" ] = game_id;
        local data_out = comm_center.call_service("Svr_IsGameLastActionSwitchBranch", z_param);
        if data_out ~= nil and data_out.is_switch_branch == 1 then
            is_switch_branch = 1;
        else
            is_switch_branch = 0;
        end
        return is_switch_branch;
     end;

     -- 格式化给web回包的module info
    get_web_rsp_module_info = function(game_id)
        local format_info = nil;
        local module_info = banner_model.get_banner_module_info_by_game_id(game_id);
        if module_info ~= nil then
            format_info = {
                name = module_info.name,
                type = module_info.type,
                game_id = module_info.game_id,
                module_url = module_info.module_url,
                background_color = module_info.background_color,
                background_image = module_info.background_image,
                image_position = module_info.image_position,
                toolBar_BG = module_info.toolBar_BG,
                toolBar_shadow = module_info.toolBar_shadow,
                download_gifts = module_info.download_gifts,
                download_report = module_info.download_report,
                gift_icon_disable = module_info.gift_icon_disable,
                gift_icon = module_info.gift_icon,
            };
        end
        return format_info;
    end;

    get_subscription_info = function(game_id)
        if nil == game_id then 
            return nil;
        end
        local list_info = banner_model.get_visible_subscription_list();
        for k, v in pairs(list_info) do
            if v["gameid"] ~= nil and 
                tonumber(v["gameid"]) == tonumber(game_id) then
                return v;
            end
        end
        for k, v in pairs(banner_model.subscription_transfered_list_info) do
            if v["gameid"] ~= nil and 
                tonumber(v["gameid"]) == tonumber(game_id) then
                return v;
            end
        end
        return nil;
    end;

    -- 判断游戏是否处于预约期内
    -- [ReturnValue]Boolean
    get_subscription_status = function(game_id)
        local sub_info = banner_model.get_subscription_info(game_id);
        if nil == sub_info then
            return false;
        end;

        if subscription_state.kStateRelease == sub_info.status    or     -- 免费游戏已全量
           subscription_state.kStatePurchasable == sub_info.status then  -- 付费游戏已全量
            return false;
        end
        return true;
    end;

    check_subscription_state = function(cur_info, new_info)
        if nil == cur_info.status or nil == new_info.status then
            return false;
        end
        if subscription_state.kStateInvalid == cur_info.status or
            subscription_state.kStateInvalid == new_info.status then
            return false;
        end
        if subscription_state.kStatePurchased == new_info.status then
            return false;
        end
        --fixme
        return cur_info.status ~= new_info.status;
    end;

    is_add_or_remove_subscribed_games = function(new_info)
        if nil == new_info or type(new_info) ~= "table" then
            return false;
        end

        if #banner_model.subscription_list_info ~= #new_info then
            return true;
        end

        for index = 1, #new_info do
            if not banner_model.is_game_in_subscription_list(tonumber(new_info[index].gameid or "0")) then
                return true;
            end
        end

        return false;
    end;

    check_subscription_app_base_info = function(game_list, auto_request)
        if nil == game_list then
            list = {};
        end

        if type(game_list) ~= 'table' then
            return false;
        end
        local result = true;
        local query_list = {};
        for i = 1, #game_list do
            local base_info = banner_model.get_game_base_info(game_list[i].gameid);
            if nil == base_info then
                result = false;
                table.insert(query_list, game_list[i].gameid);
            end
        end

        if not result and true == auto_request then
            banner_model.subscription_app_base_info_check_list = game_list;
            comm_center.call_service("Srv_ImportGameConfigDataForGameList", 
                                    { game_idList = query_list });
        end

        return result;
    end;

    update_subscription_notify_list = function(new_list)
        banner_model.has_subscription_info_changed = false;
        for i = 1, #new_list do
            local add_to_list = false;
            local show_redpoint = true;
            local info = banner_model.get_subscription_info(new_list[i].gameid);
            if nil == info then
                local base_info = banner_model.get_app_base_info(new_list[i].gameid);
                if nil == base_info then
                    base_utility.log(
                    "[banner_model]get base info failed, gameid ".. tostring(new_list[i].gameid)
                    , true);
                end
                add_to_list = true;
            elseif banner_model.check_subscription_state(info, new_list[i]) then
                add_to_list = true;
            end

            if subscription_state.kStatePurchased == new_list[i].status then
                show_redpoint = false;
            end

            if add_to_list then
                local str_gameid = tostring(new_list[i].gameid);
                base_utility.log("[banner_model]update_subscription_notify_list, show: "..tostring(show_redpoint));
                banner_model.subscription_state_notify_list[str_gameid] = {  
                    show_red_point = show_redpoint,
                    show_tips = true 
                };
                banner_model.has_subscription_info_changed = true;
            end
        end
    end;

    query_subscription_config = function(index)

        if base_utility.is_type_of_oversea_ver() then
            return;
        end

        if nil == index then
            index = 0;
        end

        local client_type = 1;
        if base_utility.is_type_of_oversea_ver() then
            client_type = 2;
        end

        local post_data = {
                data_names = "subscription_app_config",
                command = "list_all",
                params = {
                    start_page = index,
                    items_per_pager = 50
                },
                stamp = {
                    credential = {
                        agent_client_type = client_type,
                    },
                    agent_client_language = base_utility.get_currrent_language_str();
                }
            };
        base_utility.curl_request_async(banner_model.subscription_config_url
            , "banner_model.on_query_subscription_config"
            , false, nil, true, nil, base_utility.table_to_json(post_data));

    end;

    on_query_subscription_config = function(rsp)
        base_utility.log("[banner_model]subscription config ".. rsp);
        local res_tbl = base_utility.json_to_table(rsp);
        if nil == res_tbl or nil == res_tbl.result then
            return;
        end
        if 0 ~= tonumber(res_tbl.result.error_code) then
            return;
        end

        local items_count = 0;
        if nil ~= res_tbl.items and type(res_tbl.items) == "table" then
            items_count = #res_tbl.items;
            for k, v in pairs(res_tbl.items) do
                table.insert(banner_model.subscription_config_list, v);
            end
        end

        -- request more
        local total_items = tonumber(res_tbl.total_items or "0");
        local start_page = tonumber(res_tbl.start_page or "0");
        local items_per_page = tonumber(res_tbl.items_per_pager or "0");

        if total_items > (start_page * items_per_page + items_count) then
            banner_model.query_subscription_config(start_page + 1);
        end
    end;

    check_subscription_app_base_info_interval = function()
        
        base_utility.remove_interval("banner_model.check_subscription_app_base_info_interval");

        if banner_model.check_subscription_app_base_info(
            banner_model.subscription_app_base_info_check_list) then
            banner_model.on_query_subscription_list(banner_model.subscription_list_rsp_cache);
        elseif banner_model.subscription_app_base_info_check_times < 10 then
            base_utility.add_interval("banner_model.check_subscription_app_base_info_interval",
                                            1000);
            banner_model.subscription_app_base_info_check_times =
                banner_model.subscription_app_base_info_check_times + 1;
        else
            banner_model.subscription_app_base_info_check_times = 0;
            banner_model.on_query_subscription_list(banner_model.subscription_list_rsp_cache);
            base_utility.log("[banner_model]app base info check times exceeds.", true);
        end
    end;

    query_subscription_list = function()
        
        if base_utility.is_type_of_oversea_ver() then
            return;
        end


        local param = {
            tgpid = base_utility.get_tgp_id()
                };
        local post_data = "p="..base_utility.table_to_json(param);
        base_utility.curl_request_async(banner_model.subscription_list_req_url
        , "banner_model.on_query_subscription_list" , false, nil
        , true, nil, post_data);
    end;

    on_query_subscription_list = function(rsp, from_local)
        if nil == rsp then return end;
        base_utility.log("[banner_model]subscription list rsp " ..rsp);
        local rsp_tbl = base_utility.json_to_table(rsp);
        if nil == rsp_tbl then return end;
        if nil == rsp_tbl.result or 0 ~= tonumber(rsp_tbl.result) then
            return;
        end

        if true == rsp_tbl.first_subscribe then
            banner_model.subscription_first_time = 1;
        end

        local game_list = rsp_tbl.game_list;
        if nil == game_list then
            game_list = {};
        end

        if true ~= from_local then
            
            if banner_model.check_subscription_app_base_info(game_list, true) then
                -- update state
                for i = 1, #game_list do
                    banner_model.update_app_state(game_list[i].gameid);
                end
                -- check apps which should show red points or tips
                banner_model.update_subscription_notify_list(game_list);
                -- save last response to local
                banner_model.save_local_subscription_info(rsp);
            else
                base_utility.log("[banner_model]subscribed app miss base info, request now", true);
                banner_model.subscription_list_rsp_cache = rsp;
                banner_model.check_subscription_app_base_info_interval();
                return;
            end
        else
            banner_model.subscription_list_info = game_list;
            banner_model.query_games_release_status(game_list);
            return;
        end

        local update_visible_game = banner_model.is_add_or_remove_subscribed_games(game_list);

        banner_model.subscription_list_info = game_list;
        banner_model.query_games_release_status(game_list);

        -- delete unused data
        banner_model.clean_subscription_notify_list();

        -- add subscribed apps to app-list if need
        local add_games = banner_model.transfer_subscription_to_game_list();

        -- automatically download subscribed apps if allow
        banner_model.handle_autodownload_subscription();

        -- update subscription list view
        if update_visible_game or add_games then
            banner_control.update_visible_game_list();
        else
            banner_view.refresh_subscription_list();
        end
    end;

    subscription_list_sort_func = function(a, b)
        if nil == a.subscribe_time then
            return false;
        end

        if nil == b.subscribe_time then
            return true;
        end

        return tonumber(a.subscribe_time) > tonumber(b.subscribe_time);
    end;

    get_visible_subscription_list = function()
        local result = {};
        for index = 1, #banner_model.subscription_list_info do
            local item = banner_model.subscription_list_info[index];
            local game_id = tonumber(item.gameid or "0");
            local base_info = banner_model.get_app_base_info(game_id);
            if nil ~= base_info and item.status ~= subscription_state.kStateInvalid then
                table.insert(result, item);
            end
        end
        table.sort(result, banner_model.subscription_list_sort_func);
        return result;
    end;

    remove_from_subscription_list = function(game_id_or_list)
        base_utility.log("[banner_model]remove_from_subscription_list");
        local id_list = {};
        if type(game_id_or_list) == "number" then
            if banner_model.is_game_in_subscription_list(game_id_or_list) then
                table.insert(id_list, game_id_or_list);
            end
        elseif type(game_id_or_list) == "table" then
            id_list = game_id_or_list;
        end

        if #id_list == 0 then 
            return;
        end;

        base_utility.log("[banner_model]remove_from_subscription_list request");

        local param = {
            tgpid = base_utility.get_tgp_id(),
            gameid_list = id_list
        };
        local post_data = "p="..base_utility.table_to_json(param);
        base_utility.curl_request_async(banner_model.subscription_delete_req_url
        , "banner_model.on_remove_from_subscription_result" , false, nil
        , true, nil, post_data);
    end;

    on_remove_from_subscription_result = function(rsp)
        if nil == rsp then return end;
        base_utility.log("[banner_model]remove from subscription list rsp " ..rsp);
        local rsp_tbl = base_utility.json_to_table(rsp);
        if nil == rsp_tbl or (0 ~= rsp_tbl.result and 8004010 ~= rsp_tbl.result) then
            base_utility.log("[banner_model]remove from subscription fail", true);
        else
            banner_model.query_subscription_list();
        end
    end;

    load_subscription_settings = function()
        local data = {};
        data["common"] = 1;
        data["key"] = "CfgMgr.UserSysSetting.SubscriptionAutoDownloadNew";
        local config = comm_center.call_service("Svr_GetConfig", data);
        if nil ~= config and 1 == config.exits then
            local val = tonumber(config.value or "0");
            if 1 == val then
                banner_model.auto_download_subscribed_app = true;
            else
                banner_model.auto_download_subscribed_app = false;
            end
        end
        base_utility.log("[banner_model]subscription autodownload ".. tostring(banner_model.auto_download_subscribed_app));
    end;

    load_local_subscription_info = function()
        if banner_model.has_load_local_subscription_info then
            return;
        end

        local tgp_id = base_utility.get_tgp_id();
        if nil == tgp_id or 0 == tgp_id then
            return;
        end
        local data = {};
        data["common"] = 0;
        data["key"] = "app.banner.subscription."..tostring(tgp_id)..".last_info";
        local config = comm_center.call_service("Svr_GetConfig", data);
        if nil ~= config and 1 == config.exits then
            base_utility.log("local subscription info");
            banner_model.on_query_subscription_list(config.value, true);
        end

        data["key"] = "app.banner.subscription."..tostring(tgp_id)..".notify_info";
        config = comm_center.call_service("Svr_GetConfig", data);
        if nil ~= config and 1 == config.exits then
            local config_tbl = base_utility.json_to_table(config.value);
            if nil ~= config_tbl and type(config_tbl) == 'table' then
                banner_model.subscription_state_notify_list = config_tbl;
                -- fixme 某些情况下保存的数据格式错误，读取后校验一次数据
                for k, v in pairs(banner_model.subscription_state_notify_list) do
                    if type(v) ~= 'table' then
                        banner_model.subscription_state_notify_list = {};
                        break;
                    end
                end
            end
        end

        data["key"] = "app.banner.subscription."..tostring(tgp_id)..".first_subscribe";
        local config = comm_center.call_service("Svr_GetConfig", data);
        if nil ~= config and 1 == config.exits then
            local val = tonumber(config.value or "0");
            if 1 == val then
                banner_model.subscription_first_time = 1;
            end
        end

        data["key"] = "app.banner.subscription."..tostring(tgp_id)..".cancel_download";
        local config = comm_center.call_service("Svr_GetConfig", data);
        if nil ~= config and 1 == config.exits then
            local config_tbl = base_utility.json_to_table(config.value);
            if nil ~= config_tbl and type(config_tbl) == 'table' then
                banner_model.subscription_cancel_download_list = config_tbl;
            end
        end

        banner_model.has_load_local_subscription_info = true;
    end;

    save_local_subscription_info = function(rsp)
        local tgp_id = base_utility.get_tgp_id();
        local data = {};
        data["common"] = 0;

        if nil ~= rsp then
            data["key"] = "app.banner.subscription."..tostring(tgp_id)..".last_info";
            data["value"] = rsp;
            comm_center.call_service("Svr_SetConfig", data);
        end
        
        data["key"] = "app.banner.subscription."..tostring(tgp_id)..".notify_info";
        data["value"] = base_utility.table_to_json(banner_model.subscription_state_notify_list);
        comm_center.call_service("Svr_SetConfig", data);

        data["key"] = "app.banner.subscription."..tostring(tgp_id)..".first_subscribe";
        data["value"] = tostring(banner_model.subscription_first_time);
        comm_center.call_service("Svr_SetConfig", data);

        data["key"] = "app.banner.subscription."..tostring(tgp_id)..".cancel_download";
        data["value"] = base_utility.table_to_json(banner_model.subscription_cancel_download_list);
        comm_center.call_service("Svr_SetConfig", data);
    end;

    transfer_subscription_to_game_list = function()
        local gl_adapter = base_utility.get_component_adapter("IGame_library",
                 "ierd_tgp.game_library.Get_game_library_adapter();");
        if gl_adapter == nil then
            base_utility.log("[banner_model]get gl adaptor failed, transfer subscribed app failed", true);
            return false;
        end
        local remove_list = {};
        local info_list = banner_model.get_visible_subscription_list();
        for index = 1, #info_list do
            if tonumber(info_list[index].status) == subscription_state.kStatePurchased then
                local game_id = tonumber(info_list[index].gameid or "0");
                if 0 ~= game_id then
                    local cache_info = { gameid = info_list[index].gameid, 
                                         status = info_list[index].status };
                    table.insert(banner_model.subscription_transfered_list_info, cache_info);
                    gl_adapter:add_or_remove_game(game_id, true);
                    info_list[index].status = subscription_state.kStateInvalid;
                    table.insert(remove_list, game_id);
                end
            end
        end

        if #remove_list > 0 then
            banner_model.remove_from_subscription_list(remove_list);
            return true;
        end

        return false;
    end;

    handle_autodownload_subscription = function()
        
        -- check user settings
        banner_model.load_subscription_settings();
        if not banner_model.auto_download_subscribed_app then
            return;
        end

        local info_list = banner_model.get_visible_subscription_list();
        for index = 1, #info_list do
            if (tonumber(info_list[index].status) == subscription_state.kStateDownload or
                tonumber(info_list[index].status) == subscription_state.kStateMaintein)
                and not banner_model.has_game_cancel_download(info_list[index].gameid) then
                local game_id = tonumber(info_list[index].gameid or "0");
                local base_info = banner_model.get_game_base_info(game_id);
                local status = banner_model.get_app_state(game_id);
                if nil ~= base_info and ierd_tgp.game_library.GAME_STATE_NOT_INSTALLED == status then
                    local action_info = { game_id_ = game_id };
                    WGGameAction.download(action_info);
                end
            end
        end
    end;

    get_subscription_tooltip = function(game_id, state)
        if nil == game_id or nil == state then
            return "";
        end
        local config = banner_model.subscription_config_list;
        for index = 1, #config do
            if tonumber(game_id) == tonumber(config[index].game_id) then
                if subscription_state.kStateNormal == state then
                    return config[index].subscribe_tips or "";
                elseif subscription_state.kStatePurchasable == state then
                    return config[index].purchase_tips or "";
                elseif subscription_state.kStateDownload == state then
                    return config[index].download_tips or "";
                elseif subscription_state.kStateRelease == state then
                    return config[index].play_tips or "";
                end
            end
        end
        return "";
    end;

    get_subscription_game_state = function(game_id)
        local state = subscription_state.kStateInvalid;
        local info = banner_model.get_subscription_info(game_id);
        if nil ~= info and nil ~= info.status then
            state = tonumber(info.status);
        end
        return state;
    end;

    is_game_in_subscription_list = function(game_id)
        if nil == game_id then 
            return false;
        end
        local sub_list = banner_model.get_visible_subscription_list();
        for k, v in pairs(sub_list) do
            if v["gameid"] ~= nil and tonumber(v["gameid"]) == tonumber(game_id) then
                return true;
            end
        end
        return false;
    end;

    is_game_in_transfered_list = function(game_id)
        if nil == game_id then 
            return false;
        end
        local sub_list = banner_model.subscription_transfered_list_info;
        for k, v in pairs(sub_list) do
            if v["gameid"] ~= nil and tonumber(v["gameid"]) == tonumber(game_id) then
                return true;
            end
        end
        return false;
    end;

    has_game_cancel_download = function(game_id)
        if nil == game_id then 
            return false;
        end
        for k, v in pairs(banner_model.subscription_cancel_download_list) do
            if tonumber(k) == tonumber(game_id) then
                return true;
            end
        end
        return false;
    end;

    set_game_cancel_download = function(game_id, remove)
        if nil == game_id then return end;
        if remove then
            banner_model.subscription_cancel_download_list[tostring(game_id)] = nil;
        else
            banner_model.subscription_cancel_download_list[tostring(game_id)] = 1;
            banner_control.banner_report(banner_qos_action.kActionCancelDownloadSubscribed, game_id);
        end
        banner_model.save_local_subscription_info();
    end;

    is_game_in_subscription_list_svr = function(params)
        if nil ~= params and nil ~= params.game_id then
            params.is_subscribed = banner_model.is_game_in_subscription_list(params.game_id);
        end
        return params;
    end;

    get_subscription_list_svr = function(params)
        if nil == params then
            return;
        end

        local list_info = {};

        if 1 == params.type then
            list_info = banner_model.get_visible_subscription_list();
        else
            if #banner_model.subscription_list_info == 0 then
                banner_model.load_local_subscription_info();
            end
            list_info = banner_model.subscription_list_info;
        end

        if #list_info > 0 then
            params.game_list = {};
            for index = 1, #list_info do
                if list_info[index].gameid ~= nil then
                    table.insert(params.game_list, tonumber(list_info[index].gameid));
                end
            end
            
        end
        return params;
    end;

    show_game_subscription_state_red_point = function(game_id)
        if nil == game_id then
            return false;
        end
        for k, v in pairs(banner_model.subscription_state_notify_list) do
            if tonumber(k) == tonumber(game_id) then
                return v.show_red_point or false;
            end
        end
        return false;
    end;

    show_subscription_user_guide = function()
        return banner_model.subscription_first_time == 1;
    end;

    clean_subscription_notify_list = function()
        for k, v in pairs(banner_model.subscription_state_notify_list) do
            if false == v.show_red_point and false == v.show_tips then
                banner_model.subscription_state_notify_list[k] = nil;
            end
            if not banner_model.is_game_in_subscription_list(k) and
                not banner_model.is_game_in_transfered_list(k) then
                   banner_model.subscription_state_notify_list[k] = nil;
            end
        end
    end;

    set_subscription_state_read = function(game_id)
        if nil == game_id then return end;
        local str_gameid = tostring(game_id);
        if banner_model.subscription_state_notify_list[str_gameid] ~= nil then
            banner_model.subscription_state_notify_list[str_gameid].show_red_point = false;
            banner_model.clean_subscription_notify_list();
            banner_model.save_local_subscription_info();
        end
    end;

    set_subscription_state_notified = function(game_id)
        if nil == game_id then return end;
        local str_gameid = tostring(game_id);
        if banner_model.subscription_state_notify_list[str_gameid] ~= nil then
            banner_model.subscription_state_notify_list[str_gameid].show_tips = false;
            banner_model.clean_subscription_notify_list();
            banner_model.save_local_subscription_info();
        end
    end;

    set_subscription_user_guide_showed = function()
        banner_model.subscription_first_time = 0;
        banner_model.save_local_subscription_info();
    end;

    -- red point count
    get_subscription_state_changed_count = function()
        local count = 0;
        for k, v in pairs(banner_model.subscription_state_notify_list) do
            if true == v.show_red_point and banner_model.is_game_in_subscription_list(k) then
                count = count + 1;
            end
        end
        return count;
    end;

    need_show_subscription_notify_tips = function()
        for k, v in pairs(banner_model.subscription_state_notify_list) do
            if true ==  v.show_tips then
                return true;
            end
        end
        return false;
    end;

    update_app_state = function(game_id)
        local app_list = {};
        table.insert(app_list, game_id);
        comm_center.call_service("Svr_GenerateGameState", { game_id_list = app_list });
    end;

    get_app_state = function(game_id)
        if nil == game_id then
            return 0;
        end
        game_id = tonumber(game_id);
        local game_lib = base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if nil == game_lib then
            return 0;
        end
        local game_state = ierd_tgp.game_library.GameState:new();
        if nil == game_state then
            return 0;
        end;
        game_lib:get_game_state(game_id, game_state);
        return game_state.iState;
    end;

    get_app_base_info = function(game_id_)
        if nil == game_id_ then
            return;
        end

        local base_info = banner_model.get_game_base_info(game_id_);
        if nil ~= base_info then
            return base_info;
        end

        -- request from server
        --comm_center.call_service("Srv_GetGameRelateInfo", {game_id = game_id_});
    end;

    get_game_state_list = function()
        return banner_model.game_state_list;
    end;

    is_showed_in_banner_list = function(game_id)
        if game_id == nil or
                game_id == 0 or
                banner_model == nil or  banner_model.visible_game_list == nil or
                banner_model.visible_game_list.count == nil or
                banner_model.visible_game_list.game_id_list == nil then
            base_utility.log('[is_showed_in_banner_list] param error! gamee_id:' ..
                    tostring(game_id));
            return false;
        end

        for i = 0, banner_model.visible_game_list.count - 1 do
            if game_id == banner_model.visible_game_list.game_id_list[i] then
                return true;
            end
        end

        if game_utility.is_sub_in_attach_rel(game_id) and
                game_utility.canshow_sub_entry(game_id) then
            return true;
        end

        return false;
    end;

    query_games_release_status = function(game_list)
        base_utility.log("[banner_model]query_games_release_status");
        if type(game_list) ~= 'table' then
            return;
        end

        for i = 1, #game_list do
            banner_model.game_release_list[game_list[i].gameid] = false;
        end

        for i = 1, #game_list do
            banner_model.get_game_release_status_inner(game_list[i].gameid);
        end
    end;

    get_game_release_status_inner = function(game_id)
        banner_model.inner_log("[banner_model]get_game_release_status_inner, game_id: " ..tostring(game_id), true);
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if nil == game_lib then
            return;
        end

        local game_channel = game_lib:get_game_distribution_channels(game_id);
        local is_download_url_exist = game_lib:IsExistDownloadUrl(game_id);
        local game_detail_info = ierd_tgp.game_library.GameDetailInfo:new_local();
        game_lib:get_game_detail_info(game_id, game_detail_info);
        local cur_operate_phase_class = "";
        local game_main_type = nil;

        if nil ~= game_detail_info then
            cur_operate_phase_class = game_detail_info.operate_phase_class;
            game_main_type = game_detail_info.main_type;
        end
        if nil ~= game_main_type then
            if type(game_main_type) == "string" then
                game_main_type = tonumber(game_main_type);
            end
            if 1    == game_main_type        and
               nil  ~= is_download_url_exist and
               true == is_download_url_exist then
                base_utility.log("[banner_model]get_game_release_status_inner, get mmog release status");
                game_lib:GetWhiteListStatus(game_id, "banner_model.on_get_mmog_game_release_status"..tostring(game_id));
                return;
            end
        end
        if banner_model.distribution_channels.CHANNELS_RAIL == game_channel then
            local game_base_info = banner_model.get_game_base_info(game_id);
            if nil == game_base_info or nil == game_base_info.sub_type then
                return;
            end
            if 30 == game_base_info.sub_type then  -- 免费单机游戏，直接查白名单
                base_utility.log("[banner_model]get_game_release_status_inner, get rail release status");
                game_lib:GetRailGameReleaseStatus(game_id, "banner_model.on_get_rail_game_release_status"..tostring(game_id));
                return;
            else  -- 付费单机，先查权限，再查白名单
                local callback_func = rail_proxy_event.QUERY_GAME_INFO_ON_INIT_DOWNLOAD_STATU;
                local lua_table = { }
                lua_table.dest                  = "0";
                lua_table.seq_num               = "0";
                lua_table.callback_func         = callback_func;
                lua_table.data                  = { };
                lua_table.data.game_id          = game_id;
                lua_table.data.need_refund_info = 0;
                lua_table.src                   = "0";
                local rail_host = base_utility.get_component_adapter(
                    "IRailHost", "ierd_tgp.tgp_plugin.GetRailHostAdapter();");
                base_utility.log("[banner_model]get_game_release_status_inner, query authority");
                rail_host:QueryGameAuthorityInfo(base_utility.table_to_json(lua_table));
                return;
            end
        end
    end;

    on_get_game_release_status = function(event_id, json_str)
        base_utility.log("[banner_model]on_get_game_release_status called"..json_str);
        if nil == json_str then
            base_utility.log("[banner_model]on_get_game_release_status json_str is nil");
            return;
        end
        local json_data = base_utility.json_to_table(json_str);
        if nil == json_data then
            base_utility.log("[banner_model]on_get_game_release_status parse json failed");
            return;
        end

        local task_check = json_data["task_check"];
        local is_release = json_data["is_release"];
        local game_id    = json_data["game_id"];
        if nil == task_check             or
           nil == is_release             or
           nil == game_id                or
           type(is_release) ~= "boolean" or
           type(game_id)    ~= "number"  then
            base_utility.log("[banner_model]on_get_game_release_status param not valid");
            return;
        end

        if "banner_model.on_get_mmog_game_release_status"..tostring(game_id) ~= task_check and
           "banner_model.on_get_rail_game_release_status"..tostring(game_id) ~= task_check then
            return;
        end

        base_utility.log("[banner_model]on_get_game_release_status set local game release list");
        banner_model.inner_log("[banner_model]on_get_game_release_status, game_id: " ..tostring(game_id), true);
        banner_model.game_release_list[game_id] = is_release;
    end;

    on_query_game_authority_info = function(event_id, json_str)
        base_utility.log("[banner_model]on_query_game_authority_info called"..json_str);
        local table_param = base_utility.json_to_table(json_str);
        if (table_param == nil) then
            return;
        end

        local callback_func = table_param["callback_func"];
        if (callback_func == nil) then
            return;
        end
        -- 仅处理获取下载状态时的权限查询
        if (rail_proxy_event.QUERY_GAME_INFO_ON_INIT_DOWNLOAD_STATU ~= callback_func) then
            return;
        end

        if 0 == table_param.result or 0 == table_param.authority_info.result then
            return;
        end

        if 1 ~= table_param.authority_info.state then
            return;
        end

        -- 鉴权通过后再通过接口判断是否有下载权限
        local game_lib = base_utility.get_component_adapter("IGame_library",
            "ierd_tgp.game_library.Get_game_library_adapter();");
        if nil ~= game_lib then
            base_utility.log("[banner_model]on_query_game_authority_info called, get release status");
            game_lib:GetRailGameReleaseStatus(table_param.game_id,
                "banner_model.on_get_rail_game_release_status"..tostring(table_param.game_id));
        end
    end;

};

banner_model.init();
